﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Xml;

namespace for7raid.vk
{
    public class City : DependencyObject
    {

        public int Id
        {
            get { return (int)GetValue(IdProperty); }
            set { SetValue(IdProperty, value); }
        }

        public static readonly DependencyProperty IdProperty =
            DependencyProperty.Register("Id", typeof(int), typeof(City), new UIPropertyMetadata(0));


        public string Name
        {
            get { return (string)GetValue(NameProperty); }
            set { SetValue(NameProperty, value); }
        }

        public static readonly DependencyProperty NameProperty =
            DependencyProperty.Register("Name", typeof(string), typeof(City), new UIPropertyMetadata(""));

        public static List<City> FromResponse(XmlDocument doc)
        {
            return doc.SelectNodes("/response/city").OfType<XmlNode>().Select(item =>
                  new City()
                        {
                            Id = item["cid"].ParseXmlNodeAsInt(),
                            Name = item["name"].InnerText
                        }
                        ).ToList();
        }
    }
}
